/**
 * 测试
 */
function postAnswer(event) {
	var $answer = '';
	$('input[type=radio]:checked').each(function() {
		$answer += this.value + ',';
	});
	$answer = $answer.substring(0, $answer.length - 1);
	re=eval("/"+','+"/ig");
	var usrlen=$answer.match(re).length+1;//此处未考虑：没有选任何题
	var allen=$("tr").length;
	if(usrlen==allen)
		$.ajax({
			url : 'upAnswer',
			data : {
				answers : $answer
			},
			type : 'post',
			dataType : 'json',
			success : function(data) {
				if (data.message == 'true') {
					if(data.score!=null){
						console.log("成绩:----->" + data.score);
						window.location="../userExamResults";
					}
					else
						console.log("超时成绩无效！！");
				} else {
					alert("系统错误")
				}
			}
		});
	else
		alert("你还有试题未作答！");
	console.log(usrlen+'****'+allen);
}

/**
 * 计时器
 */

function display() {
	rtime = etime - ctime;
	if (rtime > 60)
		m = parseInt(rtime / 60);
	else {
		m = 0;
	}
	s = parseInt(rtime - m * 60);
	if (s < 10)
		s = "0" + s;
	document.getElementById("ltime").innerHTML = "离考试结束 :  " + m + ":" + s;
	window.setTimeout("checktime()", 1000)
}

function settimes() {
	console.log("还剩余120分钟 !")
	var time = new Date();
	hours = time.getHours();
	mins = time.getMinutes();
	secs = time.getSeconds();
	etime = hours * 3600 + mins * 60 + secs;
	examTime=document.getElementById("ltime").innerHTML;
	etime += examTime*60; //分钟数乘以60
	checktime();
}

function checktime() {
	var time = new Date();
	hours = time.getHours();
	mins = time.getMinutes();
	secs = time.getSeconds();
	ctime = hours * 3600 + mins * 60 + secs
	if (ctime >= etime) {
		expired();
	} else
		display();
}

function expired() {
	alert("时间到");
	//location.href = "http://www.sharejs.com"; // 填写要转向的网页
}